package skewreduce.lib;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public final class Particle extends Point3D implements IParticle {
    protected long id;

    public Particle() {}

    public Particle(long i,float x,float y,float z) {
        super(x,y,z);
        id = i;
    }

    public void write(DataOutput out) throws IOException {
        out.writeLong(id);
        super.write(out);
    }

    public void readFields(DataInput in) throws IOException {
        id = in.readLong();
        super.readFields(in);
    }

    public int getRecordLength() { return 20; }

    public static Particle read(DataInput in) throws IOException {
        Particle p = new Particle();
        p.readFields(in);
        return p;
    }

    public int hashCode() { return (int)id; }
    public long getID() { return id; }

    public int compareTo(IParticle x) {
        return (int)(id - x.getID());
    }

    public boolean equals(Object o) {
        if ( this == o ) return true;
        if ( o instanceof IParticle )
            return id == ((IParticle)o).getID();
        return false;
    }
}
